package com.ricky.job;


import java.util.Map;

import org.apache.log4j.Logger;

import com.ricky.core.net.abs.Request;
import com.ricky.core.net.msg.Context;
import com.ricky.handler.Default;
import com.ricky.handler.HandlerFactory;
import com.ricky.handler.IHandler;

/**
 * 用户验证
 * @author rik
 *
 */
public class Authorise implements Runnable {

	protected static Logger log = Logger.getLogger(MsgTask.class);

	@SuppressWarnings("rawtypes")
	private Context<Map<String,Object>> context;
	private Request request;
	
	@SuppressWarnings("rawtypes")
	public Authorise(Request request,Context<Map<String,Object>> context) {
		this.context=context;
		this.request=request;
	}

	@Override
	public void run() {
		String handName=context.getHead();
		String handKey=HandlerFactory.Auth_prefix+"."+handName;
		IHandler handler=request.getHandler(handKey);
		if(handler==null)
		{
			handler=HandlerFactory.createHandler(HandlerFactory.Package_authorise,handName);
			if(handler==null)
				handler=request.getHandler(Default.defaultHandName);
			request.register(handKey, handler);
		}
		
		if(handler!=null)
			handler.proccess(request,context.getContent());

	}

}
